import db from './db'
import Mock from 'mockjs'

// 读取当前用户信息
Mock.mock('productcate/list', 'get', () => {

    const result = db.select('Oppo_productcate')
    return {err: 0,result,desc: '执行成功'}
  })

Mock.mock('productcate/cate','get',() =>{
    const result = db.select('Oppo_productcate',['id','procate','orderid'],item => item.state ===2)
        .sort((a,b) => a.orderid - b.orderid)
    return { err: 0, result,desc:'执行成功'}
})
//添加
Mock.mock('productcate/add', 'post', ({ body }) => {
    const { procate='',orderid='', picurl='', state=1 } = JSON.parse(body)
  
    db.add('Oppo_productcate', { procate,picurl,orderid,state })
    return { err: 0, desc: '执行成功' }
  })
  
  // 修改
Mock.mock('productcate/edit', 'post', ({ body }) => {
      const {id, procate,orderid='', picurl='', state=1  } = JSON.parse(body)
  
      db.put('Oppo_productcate',id, { procate,picurl,orderid,state  })
      return { err: 0, desc: '执行成功' }
  })
  // 审核
Mock.mock('productcate/state', 'post', ({ body }) => {
    const { id, state } = JSON.parse(body)

    db.put('Oppo_productcate', id, { state })
    return { err: 0, desc: '执行成功' }
  })


  // 删除
Mock.mock('productcate/del', 'post', ({ body }) => {
    const { ids } = JSON.parse(body)
    db.delete('Oppo_productcate', ids)
    return {
      err: 0,
      desc: '执行成功'
    }
})